﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _09_InsertionSort
{
    class Program
    {
        static int BiggestNumberFromStartIndex(int[] array, int startIndex)
        {
            int currentBiggestNumber = startIndex;
            for (int index = startIndex; index < array.Length; index++)
            {
                if (array[index] > array[currentBiggestNumber])
                {
                    currentBiggestNumber = index;
                }
            }

            return currentBiggestNumber;
        }

        static void InsertionSortDescending(int[] array)
        {
            for (int index = 0; index < array.Length; index++)
            {
                int swapValue = array[index];
                int indexOfBiggestNumber = BiggestNumberFromStartIndex(array, index);
                array[index] = array[indexOfBiggestNumber];

                array[indexOfBiggestNumber] = swapValue;
                //array[BiggestNumberFromStartIndex(array, index)] = swapValue;
            }
        }       

        static void Main(string[] args)
        {
            int[] unsortedArray = { 9, 2, 1, 4, 213, 5 };
            
            //InsertionSort(unsortedArray);

            InsertionSortDescending(unsortedArray);

            foreach (var item in unsortedArray)
            {
                Console.Write(item +" ");   
            }
             
            Console.WriteLine();
            foreach (var item in unsortedArray.Reverse())
            {
                Console.Write(item + " ");
            }

        }
    }
}
